package com.static_;

/**
 * @Author 小闽
 * @Date 2024/9/4 20:06
 * @PackageName: com.static_
 * @ClassName: ChildGame
 * @Description: 类变量
 * @Version 1.0
 */
public class ChildGame {
    public static void main(String[] args) {
        int count = 1;
        Child child1 = new Child("白骨精");
        //child1.join();
        //count++;
        child1.count++;
        Child child2 = new Child("狐狸精");
        //child2.join();
        //count++;
        child2.count++;
        Child child3 = new Child("老鼠精");
        //child3.join();
        //count++;
        child3.count++;

        System.out.println(child1);
        System.out.println(child2);
        System.out.println(child3);
        System.out.println("共有" + child1.count++ +"个小孩加入了游戏...");
    }
}

class Child {
    private String name;
    // 定义一个类变量，用于对所有的实例对象能够共享此变量中的数据。
    public static int count;
    public Child(String name) {
        this.name = name;
    }
    public void join(){
        System.out.println(name + "加入了游戏...");
    }
}
